import json
from dataclasses import dataclass

from src.control_pkg.scripts.dji_api.drone.enums.drone_state_push_enum import DroneModeCodeEnum, LandingTypeEnum, LandingProtectionTypeEnum


@dataclass
class Data:
    landing_protection_type: LandingProtectionTypeEnum = -1
    landing_type: LandingTypeEnum = -1
    mode_code: DroneModeCodeEnum = -1
    night_lights_state: int = 0
    stealth_state: int = 0

"""
    飞行器状态信息上报
    Topic: thing/product/{gateway_sn}/drc/up  
"""

@dataclass
class DrcDroneInfo:
    data: Data = Data()
    method: str = ""
    seq: int = 0
    @classmethod
    def from_json(cls, json_str: str) :
        data = json.loads(json_str)
        return cls(data=Data(**data["data"]), method=data["method"], seq=data["seq"])


    def to_json(self) -> str:
        return json.dumps(self, default=lambda o: o.__dict__, indent=4)


if __name__ == '__main__':
    jstr = """
        {
        "data": {
            "landing_protection_type": 0,
            "landing_type": 1,
            "mode_code": 0,
            "night_lights_state": 0,
            "stealth_state": 0
        },
        "method": "drc_drone_state_push",
        "seq": 1
        }
    """
